package com.example.myapplication;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

public class AddArticleActivity extends AppCompatActivity {

    private EditText etTitle, etContent;
    private Button btnSubmit;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_add_article);

        // 初始化视图
        etTitle = findViewById(R.id.etArticleTitle);
        etContent = findViewById(R.id.etArticleContent);
        btnSubmit = findViewById(R.id.btnSubmitArticle);

        // 提交按钮点击事件
        btnSubmit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                submitArticle();
            }
        });
    }

    private void submitArticle() {
        String title = etTitle.getText().toString().trim();
        String content = etContent.getText().toString().trim();

        if (title.isEmpty()) {
            Toast.makeText(this, "请输入文章标题", Toast.LENGTH_SHORT).show();
            return;
        }

        if (content.isEmpty()) {
            Toast.makeText(this, "请输入文章内容", Toast.LENGTH_SHORT).show();
            return;
        }

        // 这里应该是保存文章的逻辑，实际项目中可能是网络请求或数据库操作
        // 这里只是演示，所以只显示Toast
        Toast.makeText(this, "文章提交成功：" + title, Toast.LENGTH_SHORT).show();
        
        // 关闭当前Activity
        finish();
    }
}